package com.lisa.sobrio;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class SplashScreen extends Activity{

		//ImageView s, o, b, r, i, o2;
		//Animation a1,a2,a3,a4,a5,a6;
		Animation enter;
		ImageView sobrio;
		
	   private static String ETIQUETA = SplashScreen.class.getName();
	   private static long DURATA = 4;    // Timer in sec splash
	   @Override
	   protected void onCreate(Bundle savedInstanceState) {
	      super.onCreate(savedInstanceState);
	 
	      this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // senza title bar
	      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // senza notification bar
	 
	      setContentView(R.layout.activity_splash);
	      sobrio = (ImageView) findViewById(R.id.splash);

	      //animazione
	      enter = AnimationUtils.loadAnimation(this, R.anim.translate_anim_enter);
	      
	      sobrio.startAnimation(enter);
	/*      s = (ImageView) findViewById(R.id.s);
	      o = (ImageView) findViewById(R.id.o_1);
	      b = (ImageView) findViewById(R.id.b);
	      r = (ImageView) findViewById(R.id.r);
	      i = (ImageView) findViewById(R.id.i);
	      o2 = (ImageView) findViewById(R.id.o_2);
	      
	      AnimationSet diceset = new AnimationSet(true);
			
			a1 = AnimationUtils.loadAnimation(this, R.anim.anim_splash);
			s.startAnimation(a1);
			a1.reset();
			diceset.addAnimation(a1);
						
			a2 = (Animation) AnimationUtils.loadAnimation(this, R.anim.anim_splash);
			a2.setStartOffset(200);
			o.startAnimation(a2);
			a2.reset();
			diceset.addAnimation(a2);
						
			a3 = (Animation) AnimationUtils.loadAnimation(this, R.anim.anim_splash);			
			a3.setStartOffset(400);
			b.startAnimation(a3);
			a3.reset();
			diceset.addAnimation(a3);
			
			a4 = (Animation) AnimationUtils.loadAnimation(this, R.anim.anim_splash);			
			a4.setStartOffset(600);
			r.startAnimation(a4);
			a4.reset();
			diceset.addAnimation(a4);
			
			a5 = (Animation) AnimationUtils.loadAnimation(this, R.anim.anim_splash);			
			a5.setStartOffset(800);
			i.startAnimation(a5);
			a5.reset();
			diceset.addAnimation(a5);
			
			a6 = (Animation) AnimationUtils.loadAnimation(this, R.anim.anim_splash);			
			a6.setStartOffset(1000);
			o2.startAnimation(a6);
			a6.reset();
			diceset.addAnimation(a6);
						
			startAnimation(diceset);
			*/
	 
	      // Inizio timer e inizio main activity
	      IntentLauncher launcher = new IntentLauncher();
	      launcher.start();

	   }
	 
	  
	private void startAnimation(AnimationSet diceset) {
		// TODO Auto-generated method stub
		
	}


	private class IntentLauncher extends Thread {
	      @Override
	      
	      public void run() {
	         try {
	            // Inizia Sleep
	            Thread.sleep(DURATA*1000);
	         } catch (Exception e) {
	            Log.e(ETIQUETA, e.getMessage());
	         }
	         
	         // Inizia main activity
	         Intent lamain = new Intent(SplashScreen.this, MainActivity.class);
	         SplashScreen.this.startActivity(lamain);
	         SplashScreen.this.finish();

	      }
	   }
	
}
